package cn.iocoder.yudao.module.api.shop.category.eums;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.business.basic.enums.EnumCodable;
import com.baomidou.mybatisplus.annotation.EnumValue;
import jakarta.annotation.Nonnull;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

/**
 * 店铺主营类目编码（即店铺种类）
 *
 * @author 山野羡民（1032694760@qq.com）
 */
@RequiredArgsConstructor
@Getter
public enum ShopCategoryCodeEnum implements EnumCodable {

    UNDEFINED("undefined", "未知"),
    GROUPON("groupon", "团购类"),
    MALL("mall", "购物类"),
    FOOD("food", "美食类"),
    HOTEL("hotel", "住宿类"),
    ENTERTAINMENT("entertainment", "娱乐类"),
    HOUSEKEEPING("housekeeping", "家政类"),
    SCENIC("scenic", "景区类"),
    VIRTUAL("virtual", "虚拟类"),
    OTHER("other", "其他类"),
    ;

    @EnumValue
    private final String code;
    private final String name;

    @Nonnull
    public static ShopCategoryCodeEnum codeOf(String code) {
        return Stream.of(values())
                .filter(p -> Objects.equals(p.code, code))
                .findAny()
                .orElse(UNDEFINED);
    }

    @Nonnull
    public static Set<String> getO2oCodes() {
        return CollUtil.newHashSet(
                FOOD.getCode(),
                HOTEL.getCode(),
                ENTERTAINMENT.getCode(),
                HOUSEKEEPING.getCode(),
                SCENIC.getCode()
        );
    }

    public static boolean isO2o(String code) {
        return getO2oCodes().contains(code);
    }

}
